package com.shop.entity;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.MapKeyClass;
import javax.persistence.MapKeyColumn;
import javax.persistence.OrderColumn;
import javax.persistence.Table;
@Entity
@Table(name="person_inf")
public class Person {
	@Id 
	@Column(name="person_id")
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private Integer id;
	
	private String name;
	private int age;
	
	//集合属性，保留该对象关联的学校
	@ElementCollection(targetClass=String.class)
	//映射保存集合属性的表
	@CollectionTable(name="person_schools", joinColumns=@JoinColumn( name="person_id",nullable=false ))
	//指定保存集合元素的列 school_name
	@Column(name="school_name")
	//映射集合元素索引的列
	@OrderColumn(name="list_order")
	private List<String> schools = new ArrayList<String>();

	//集合属性Set，保留该对象关联的图书
	@ElementCollection(targetClass=String.class)
	//映射保存集合属性的表
	@CollectionTable(name="person_books", joinColumns=@JoinColumn( name="person_id",nullable=false ))
	//指定保存集合元素的列 book_name
	@Column(name="book_name")
	private Set<String> books = new HashSet<String>();
	
	//数组属性，保留关联的电影信息
	@ElementCollection(targetClass=String.class)
	@CollectionTable(name="person_movies",joinColumns=@JoinColumn(name="person_id",nullable=false))
	@Column(name="movie_name")
	@OrderColumn(name="movie_num")
	private String[] movies;
	
	
	//Map属性，存储成绩信息
	@ElementCollection(targetClass=Float.class)
	@CollectionTable(name="person_scores",joinColumns=@JoinColumn(name="person_id",nullable=false))
	@Column(name="mark")
	@MapKeyColumn(name="subject_name")
	@MapKeyClass(String.class)
	private Map<String,Float> scores = new HashMap<String,Float>();
	
	
	//映射组件属性
	private Name names;
	
	
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public List<String> getSchools() {
		return schools;
	}

	public void setSchools(List<String> schools) {
		this.schools = schools;
	}

	public Set<String> getBooks() {
		return books;
	}

	public void setBooks(Set<String> books) {
		this.books = books;
	}

	public String[] getMovies() {
		return movies;
	}

	public void setMovies(String[] movies) {
		this.movies = movies;
	}

	public Map<String, Float> getScores() {
		return scores;
	}

	public void setScores(Map<String, Float> scores) {
		this.scores = scores;
	}

	public Name getNames() {
		return names;
	}

	public void setNames(Name names) {
		this.names = names;
	}
	
	
}
